

/**
 * 编写 操作数据库的费率 函数，并导出不同险种的操作费率函数
 * 
 */

let {connection,connect} =  require('../connect')


//  查询 私家车意外险 费率条数
export function getPrCarRate(id) {

    console.log("\n getPrCarRate---------->")
    
    return new Promise((resolve, reject) => {

        if (!connection.isConnected) {
            connection=connect();
        }

        connection.query(`SELECT * FROM pr_car_rate WHERE pr_car_insurance_id =  ${id}`, function (error, results, fields) {

            if (error) {
                reject(error);
                throw error;
            };

            console.log(`\n查出 pr_car_rate 费率：${results.length}条\n`);

            resolve({
                total: results.length,
                id: id
            });

        });
    })
}

//  查询 终身重疾 费率条数
export function getLifeIllnessRate(id) {

    console.log("\n getLifeIllnessRate---------->")
    
    return new Promise((resolve, reject) => {

        if (!connection.isConnected) {
            connection=connect();
        }

        connection.query(`SELECT r.* FROM life_illness_rate r WHERE r.life_illness_insurance_id =  ${id}`, function (error, results, fields) {

            if (error) {
                reject(error);
                throw error;
            };

            console.log(`\n查出 life_illness_rate 费率：${results.length} 条,\n\n`,results,"\n\n");

            resolve({
                total: results.length,
                id: id
            });

        });
    })
}

//  查询 定期重疾 费率条数
export function getReIllnessRate(id) {
    

    console.log("\n getReIllnessRate---------->")
    
    return new Promise((resolve, reject) => {

        if (!connection.isConnected) {
            connection=connect();
        }

        connection.query(`SELECT * FROM re_illness_rate WHERE re_illness_insurance_id =  ${id}`, function (error, results, fields) {

            if (error) {
                reject(error);
                throw error;
            };

            console.log(`\n查出 re_illness_rate 费率：${results.length}条\n`);

            resolve({
                total: results.length,
                id: id
            });

        });
    })
}

//  查询 定期寿险 费率条数
export function getReLifeRate(id) {
    

    console.log("\n getReLifeRate---------->")
    
    return new Promise((resolve, reject) => {

        if (!connection.isConnected) {
            connection=connect();
        }

        connection.query(`SELECT * FROM re_life_rate WHERE regular_life_insurance_id =  ${id}`, function (error, results, fields) {

            if (error) {
                reject(error);
                throw error;
            };

            console.log(`\n查出 re_life_rate 费率：${results.length}条\n`);

            resolve({
                total: results.length,
                id: id
            });

        });
    })
}